﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using EntLibContrib.Query;

namespace EntLibContrib.Mapping.QuickStart.DomainObjects
{
	[SuperMapper(Name = "Owner Mapper", TypeColumnValue = "O")]
	public class OrganisationOwner : Owner
	{
		private Guid organisationId;
		private Organisation organisation;

		[Map()]
		public Guid OrganisationId
		{
			get { return organisationId; }
			set { organisationId = value; }
		}

		public Organisation Organisation
		{
			get
			{
				if (organisation == null)
				{
					if (organisationId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", organisationId);
						organisation = MapperFactory.CreateMapper("Organisation Mapper").ToDomainObject<Organisation>(QueryFactory.CreateQuery("Read Organisation By Id").ExecuteForRead(parameters));
					}
				}

				return organisation;
			}
		}

		public override string Name
		{
			get { return Organisation.Name; }
		}

		public OrganisationOwner()
		{ }
	}
}
